home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2944 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. From: John Vilburn <JVilburn@novell.com>
  2. Organization: Novell, Inc.
  3. X-Mailer: Mozilla 1.2N (Windows; I; 32bit)
  4. MIME-Version: 1.0
  5. Newsgroups: comp.lang.c
  6. Subject: Re: sscanf problems
  7. References: <4e4c2v$j2g@mathserv.mps.ohio-state.edu>
  8. Content-Transfer-Encoding: 7bit
  9. Content-Type: text/plain; charset=us-ascii
  10. NNTP-Posting-Host: jvilburn.npd.provo.novell.com
  11. Message-ID: <3106fabd.0@news.provo.novell.com>
  12. Date: 25 Jan 96 03:36:29 GMT
  13. Path: news.provo.novell.com!
  14.  
  15. Chris Mongold <cmongold@magnus.acs.ohio-state.edu> wrote:
  16. >Hello,
  17. >    I'm sorry if this is an inappropriate topic, but I've tried
  18. >everything else.  I can't seem to get sscanf to to separate a string
  19. >into various variable types.  Here is an example:
  20. >
  21. >#include <stdio.h>
  22. >
  23. >void main()
  24. >{
  25. >char input[20], crap[17], segment[6], seg_len[3], begin[3], load[3];
  26. >int type;
  27. >FILE *fp;
  28. >
  29. >printf("File: ");
  30. >gets(input);
  31. >
  32. >fp = fopen(input, "r");
  33. >
  34. >while(!feof(fp))
  35. >{
  36. >fgets(crap, 17, fp);
  37. >sscanf(crap, "%d%3s%6s%3s%3s", type, begin, segment, seg_len, load);
  38. >printf("%d %3s %6s %3s %3s", type, begin, segment, seg_len, load);
  39. >
  40. >}
  41. >}
  42. >No matter what I do, it always 'bus errors' when I sscanf.  I've tried
  43. >it several different ways, including making crap larger, but to
  44. >no avail.  If anyone can help me, I would greatly appreciate it.
  45. >Please respond to cmongold@magnus.acs.ohio-state.edu 
  46. >
  47. >Thanks,
  48. >
  49. >Chris 
  50.  
  51. I think you may be telling sscanf that "type" can hold 3 
  52. characters. It can actually hold only 2 because the string 
  53. needs to be null terminated. The same is true for the other 
  54. destination strings. Try declaring each of them to be one byte 
  55. longer.
  56.  
  57.